Authoring Custom Tools

Introduction

Apex supports creation of ‘Custom” tools that look and feel just like the standard tools delivered with Apex, but with capabilities that are implemented using the Apex Python scripting API. Custom tools extend the ‘batc h’ capabilities provided by Macro Record/Play by adding support for user inputs (and outputs) using user interfaces (UIs) that look and feel just like standard Apex tools. This capability can greatly enhance the functionality of a script by enabling users to interact with it through the tool user interface, providing free form input parameters, selecting pre-defined options and even selecting objects from the graphics/tree views to use as targets within the script. In addition to accepting input from the user, custom tools also enable display of data provided/generated by the script to the user using the same tool UI. Custom tools enable configuration of pick filters, support automatic and/or manual tool execution modes and support integrated workflow instructions, tool tips, advanced tool tips (including movies) and integrated, keyword searchable documentation.

Most of the capabilities described above are demonstrated by example in a collection of ‘Demo Tools’ that are provided as part of the Apex installation. These demo tools are intended to show how to create tools using the Apex scripting API and are focused mostly on the mechanics of authoring a tool with less emphasis on the actual tool utility. Apex installations also include ‘Apex Utilities’ – a suite of Custom Tools developed by the Apex Community that leverage ethe Apex Custom Tool capability to deliver useful modelling and simulation functions that significantly extend the core capabilities of Apex.

Configuration of custom tools

Apex custom tools use the same organizational structure as standard Apex tools as shown below. A ‘Tool Palette’ can be launched from a “Tool palette launcher” button hosted in the toolbar region on the right hand side of the application. Each palette can contain one or more “Tool Groups” and each Tool Group can contain one or more “Tools”. Tools are displayed using the icons and/or names in the same way as standard Apex tools.

In order for a tool palette to be displayed within the Apex UI, files associated with the palette, groups and tools must be organized within a specified folder structure which must be visible to the computer on which Apex is being executed. Multiple tool palettes (and their associated groups and tools) may be present withing a single top level folder.

Folders containing collections of tool palettes may then be configured for display within Apex using the Options/Application Settings/Custom Tools menu shown below.

The Apex installation includes two separate tool palette folders, one each for ''Demo Tools'' and ‘'Apex Utilities'’. During installation, a new file ‘CustomToolPalettesSetting<APEX_VERSION_INFO>.xml’ is created in the users ‘MSC_Apex Workspace’ folder where <APEX_VERSION_INFO> is a string representing the Apex release version. Since this string is different for each Apex release, it is possible to support multiple Apex versions, each with its own Custom Tool set on a single computer.

When developing your own custom tools, we recommend that you create your own folders to host your tools instead of extending the ones installed by Apex – this makes it easier to retain your custom tools when upgrading to a new release of Apex.

Custom tool folder structure

As mentioned previously, the structure of the tool palette folders must be correct in order for the tools to be displayed correctly. The folder structure basically reflects the hierarchy of the custom tools. Consider the folder containing the tool palettes as the top level, then,

  • ·The files for a tool palette are contained within a folder that is itself parented by the top level folder.
    • Within each folder associated with a palette there must be a file named ‘palette.xml’. This file provides information about the palette and the tool groups that it contains. The detailed content and format of this file will be described later.
    • Within each folder associated with a palette there must be a folder named ‘res’. This folder currently contains only the icon that is used to identify the tool palette in the Apex UI.
  • ·The files for a Tool Group are contained within a folder that is itself parented by the tool palette folder.
    • Within each folder associated with a tool group there must be a file named ‘group.xml’. This file provides information about the tool group and the tools that it contains. The detailed content and format of this file will be described later.
  • ·The files for a Tool are contained within a folder that is itself parented by the tool group folder.
    • Within each folder associated with a tool there must be a file named ‘tool.xml’. This file provides information about the tool. The detailed content and format of this file will be described later.  
    • The files for a Tool are shared between two folders – ‘src’ and ‘res’ both of which are parented by the tool folder. The Python code that implements both the business logic and the UI for the tool is placed in the ‘src’ folder. Icons and other images used by the tool are placed in the ‘res’ folder

An example of the above tool palette folder structure containing a single tool palette with two tool groups, each of which contains two tools is shown below

Tool palettes folder

  Tool palette 1

   palette.xml

   res

   Tool group 1

     group.xml

     Tool 1

      tool.xml

      src

      res

     Tool 2

      tool.xml

      src

      res

   Tool group 2

     group.xml

     Tool 3

      tool.xml

      src

      res

     Tool 4

      tool.xml

      src

      res

palette.xml

Each tool palette folder must contain a single palette.xml file. This file provides information about the tool palette including,

  • the name of the tool palette, which may be different from the folder name. This name is displayed as tool tip text on the tool palette icon and also at the top of the tool palette when it is displayed
  • The name of the icon associated with this tool palette. Icons can be provided as .jpg files measuring 36x36 pixels. The icon must be present in the ‘res’ folder within the tool palette folder
  • A description for this tool palette. The description is not currently used for tools developed by end users, however for tools distributed with Apex, it is used to provide basic documentation for the tool palette
  • A list of the tool groups that will be included in this tool palette. Each tool group is identified using the tool group name that is defined within the group.xml file for each group. The tool groups will be displayed on the tool palette in the order that they are defined here

 

<?xml version="1.0" ?>

<configurations xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="">http://www.w3.org/2001/XMLSchema-instance">

  <palette>

    <name>Interoperability Utilities</name>

    <icon>interoperabilityUtilities.png</icon>

    <description>Interoperability Utilties</description>

    <tool_groups Version="1.0" LastUpdate="20140707">

    <group Name="Import"/>

    <group Name="Export"/>

    <group Name="CAE Fatigue"/>

    <group Name="Nonlinear"/>

    <group Name="Hypersizer Utils"/>

    </tool_groups>

  </palette>

</configurations>

 

 

 

group.xml

Each tool group folder must contain a single group.xml file. This file provides information about the tool group including,

  • The name of the tool group. This name will be used to identify the group in the tool palette UI and can be different the tool group folder name
  • A description of the tool group. The description is not currently used for tools developed by end users, however for tools distributed with Apex, it is used to provide basic documentation for the tool group
  • A list of the tools that will be included in this tool group. Each tool is identified using the tool name that is defined within the tool.xml file for each tool. The tools will be displayed within the tool group region of the tool palette in the order that they are defined here

 

<?xml version="1.0" ?>

<configurations xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="">http://www.w3.org/2001/XMLSchema-instance">

  <tool_group>

    <name>Export</name>

    <description>Description is missing for this Tool Group </description>

    <tools>

      <tool Name="Contact Model Creation Utility"/>

      <tool Name="CreateStudy"/>

      <tool Name="EditContacts"/>

      <tool Name="Export112"/>

      <tool Name="ExportUtils"/>

    </tools>

    <Version>1.0</Version>

  </tool_group>

</configurations>

 

 

tool.xml

Each tool folder must contain a single tool.xml file. This file provides information about the tool including,

  • The name of the tool. This name will be used to identify the tool on the palette UI and can be different the tool folder name
  • The name of the icon associated with this tool. Icons can be provided as .jpg files measuring 36x36 pixels. The icon must be present in the ‘res’ folder within the tool folder
  • A description of the tool. The description is currently used to provide based “Advanced tooltip’ content for the tool. For tools distributed with Apex, it is used to provide basic documentation for the tool
  • The type of the tool. Supported options for ‘tooltype’ are ‘ui-tool’ and ‘batch_tool’.
  • The name of the script that will be executed when the tool is invoked. For tools that include a tool user interface (tooltype = ui-tool) this will be the name of the Python file that provides the UI implementation. For batch tools, this will be the name of the Python file that implements the functionality of the tool. In both cases, the file must be present in the ‘src’ folder within this Tool folder

 

<?xml version="1.0" ?>

<configurations xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="">http://www.w3.org/2001/XMLSchema-instance">

  <tool>

    <name>Import Materials</name>

    <icon>bdfImport.png</icon>

    <description>Import material(s) from bdf</description>

    <tooltype>ui_tool</tooltype>

    <runfile>bdfImport_ui.py</runfile>

    <Version>1.0</Version>

  </tool>

</configurations>

 

Enable custom tools in Post

The "post_mode" key can take three values: "Yes," "No," and "Only." It is an optional key. If the key is set to "Yes," the tool will appear in both Pre and Post. If the key is set to "Only," it will only appear in Post. If the value is unset or set to "No," the tool will only appear in Pre. Apex will then display only tools that are flagged as "Yes" or "Only" in Post.

 

<?xml version="1.0" ?>
<configurations xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<tool>
<name>Auto Create VMT</name>
<icon>autoCreateVMT.png</icon>
<post_mode>Only</post_mode>
<description>auto creates VMT plots</description>
<tooltype>ui_tool</tooltype>
<runfile>auAutoCreateVMT_ui.py</runfile>
<Version>1.0</Version>
</tool>
</configurations>